# !/usr/bin/env python
# coding=utf-8
# @Time    : 2017/12/21 11:08
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/wx_server_prototype.git
# @File    : my_file.py
# @Software: PyCharm
# @Version: 3.5.4
import json
import yaml


def save_json_file(data_dict, path):
    with open(path, 'w', encoding='utf-8') as json_file:
        json_file.write(json.dumps(data_dict, ensure_ascii=False))


def load_json_file(path):
	with open(path, mode='r', encoding='utf-8') as json_file:
		data = json.load(json_file)
		return data


def read_file(path):
    """
    循环读取文件，避免文件过大导致缓冲区过大

    :param path:
    :return:
    """
    BLOCK_SIZE = 10240
    with open(path, 'rb') as f:
        while True:
            block = f.read(BLOCK_SIZE)
            if block:
                yield block
            else:
                return


if __name__ == '__main__':
	# print load_json_file('../resource/ui.json')
	# for data_str in read_file(r'C:\Users\yongwang\Downloads\VisioProfessional_x86_zh-cn.exe'):
     #    data_byte = bytes(data_str)
     #    print(data_byte[0:1], type(data_byte), len(data_byte))
	import chardet
	data_dict = load_json_file('../resource/menu.json')
	print(data_dict)
	bbb = json.dumps(data_dict).encode('utf-8')
	print(bbb, chardet.detect(bbb))
	ccc = '山东分公司地方fdhfghfgh'.encode('utf-8')
	print(chardet.detect(ccc))
	# save_json_file(data_dict, 'sssss.json')



